<template>
  <div class="demo">
    名字：{{name}}，地址：{{address}}
  </div>
</template>

<script>
import pubsub from "pubsub-js";
export default {
  name:'School',
  data(){
    return {
      name:"xxx学校",
      address:"china",
    }
  },
  mounted() {
    // 订阅消息
    this.pubId = pubsub.subscribe('hello',(msgName,data)=>{
      console.log('hello消息的回调执行了',msgName,data);
    })  
  },
  beforeDestroy() {
    // 取消订阅
    pubsub.unsubscribe(pubId)
  },
}
</script>

<style scoped>
  .demo {
    background-color: #ccc;
  }
</style>